package main

import (
	"gitee.com/536464346/asynctask/task"
	"gopkg.in/ini.v1"
	"log"
)

var cfg *ini.File

const CFG_DATA = `
[db]
dblink=
[nsq]
nsqlookupd=
`

func main() {

	nsqSec, _ := cfg.GetSection("nsq")
	c := task.NewCollect(nsqSec.Key("nsqlookupd").String())
	c.AddHandler("deal_experts_cate", "ch", task.DealCateMsg)
	c.AddHandler("deal_answertag_to_ids", "ch", task.DealAnswerMsg)
	c.Run()

	c.Wait()
}

func init() {
	var err error
	cfg, _ = ini.Load([]byte(CFG_DATA), "./main.ini")

	dbSec, _ := cfg.GetSection("db")
	err = task.NewEngine(dbSec.Key("dblink").String())
	if err != nil {
		log.Fatal("connect mysql error")
	}
	redisSec, _ := cfg.GetSection("redis")
	db, _ := redisSec.Key("db").Int()
	err = task.NewRedis(redisSec.Key("host").String(), db)

	if err != nil {
		log.Fatal("connect mysql error")
	}
}
